package xyz.lxbq.utils;

import lombok.Data;
import xyz.lxbq.pojo.Depart;

import java.util.List;

/**
 * @author XuHu
 * @version 1.0
 * @date 2020/10/15 15:51
 */
@Data
public class PageUtils<T> {
    private int pageIndex; //当前页码
    private int pageSize;  //页面大小
    private int allCount;  //总条数
    private int pageCount; //总页数

    private int numberStart; //开始页码
    private int numberEnd;  //结束页码

    private List<T> recordsl;

    public PageUtils(int pageIndex, int pageSize, int allCount, List<T> recordsl) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.allCount = allCount;
        this.recordsl = recordsl;


        //计算总页数
        this.pageCount=( allCount%pageSize==0)?(allCount/pageSize):(allCount/pageSize+1);
        //如果 总条数 % 页面大小==0 则 总页数就等于相除  反之相除后加一

        //计算分页
        if(pageCount <= 5){
            this.numberStart = 1;
            this.numberEnd = pageCount;
        }else{
            this.numberStart = pageIndex -2;
            this.numberEnd = numberStart +5;
            if(numberEnd > pageCount){
                this.numberStart = pageCount - 5;
                this.numberEnd = pageCount;
            }else if(numberStart < 1){
                this.numberStart = 1;
                this.numberEnd = numberStart + 5;
            }
        }
    }


}
